package com.qzsoft.zhjd.cement.modules.cementhomepage.controller;

import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.cement.modules.cementhomepage.dto.CementMonthAndYearCountDto;
import com.qzsoft.zhjd.cement.modules.cementhomepage.dto.CementMonthCountDto;
import com.qzsoft.zhjd.cement.modules.cementhomepage.service.CementHomePageService;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName CementHomePageController
 * @Description 水稳拌和站首页
 * @author linhuawei
 * @since 2022-01-10
 */
@RestController
@RequestMapping("/api/cementHomePage")
public class CementHomePageController {

    @Autowired
    private CementHomePageService cementHomePageService;

    /**
     * @Title countByYear
     * @Description 养护基地指定年份产量统计
     * @param baseCode 养护基地编码
     * @param year     统计年份
     * @return 产量统计
     */
    @GetMapping("countByYear")
    public Result<BigDecimal> countByYear(@RequestParam(required = true) String baseCode,
            @RequestParam(required = true) String year) {
        BigDecimal data = cementHomePageService.countByYear(baseCode, year);
        return ResultUtils.ok(data);
    }

    /**
     * @Title countForMonth
     * @Description 养护基地指定年份月产量统计
     * @param baseCode 养护基地编码
     * @param year     统计年份
     * @return 月产量统计
     */
    @GetMapping("countForMonth")
    public Result<List<CementMonthCountDto>> countForMonth(@RequestParam(required = true) String baseCode,
            @RequestParam(required = true) String year) {
        List<CementMonthCountDto> data = cementHomePageService.countForMonth(baseCode, year);
        return ResultUtils.ok(data);
    }

    /**
     * @Title getCountByMonthAndYear
     * @Description 获取指定月份、年度产量
     * @param baseCode 基地编号
     * @param month 月份
     * @param year  年份
     * @return 指定月份、年度产量
     */
    @GetMapping("/getCountByMonthAndYear")
    public Result<CementMonthAndYearCountDto> getCountByMonthAndYear(@RequestParam(required = true) String baseCode,
            @RequestParam(required = false) String month, @RequestParam(required = false) String year) {
        CementMonthAndYearCountDto data = cementHomePageService.getCountByMonthAndYear(baseCode, month, year);
        return ResultUtils.ok(data);
    }

}
